package br.fagoc.easyds.util;

import java.util.Hashtable;

import br.fagoc.easyds.ui.jgraph.GraphCellManipulator;

import com.mxgraph.util.mxConstants;
import com.mxgraph.view.mxGraph;
import com.mxgraph.view.mxStylesheet;

public class JGraphFactory {
	
	private static mxGraph graph = null;
	
	public static final String RECTANGULAR_STYLE = "RectangularStyle";
	public static final String RECTANGULAR_STYLE_HIGHLIGHTED = "RectangularStyleHighlighted";
	public static final String ELLIPSE_STYLE = "Ellipse";
	public static final String EDGE_STYLE = "strokeWidth=2;strokeColor=#34526C";
	
	public static mxGraph getGraph() {
		if(graph == null){
			initializeGraph();
		}
		
		return graph;
	}
	
	private static mxGraph initializeGraph() {
		graph = new mxGraph();
//		graph.setCellsEditable(false);
//		graph.setCellsMovable(false);
//		graph.setCellsResizable(false);
//		graph.setCellsSelectable(false);
//		graph.setCellsBendable(false);
//		graph.setEdgeLabelsMovable(false);
//		graph.setGridEnabled(false);
		
		Hashtable<String, Object> ellipseStyle = new Hashtable<String, Object>();
		ellipseStyle.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE);
		ellipseStyle.put(mxConstants.STYLE_FILLCOLOR, "#8FB0D2");
		ellipseStyle.put(mxConstants.STYLE_STROKECOLOR, "#34526C");
		ellipseStyle.put(mxConstants.STYLE_STROKEWIDTH, 1.2);
		ellipseStyle.put(mxConstants.STYLE_FONTCOLOR, "#FFFFFF");
		ellipseStyle.put(mxConstants.STYLE_FONTFAMILY, "verdana");
		ellipseStyle.put(mxConstants.STYLE_FONTSTYLE, mxConstants.FONT_BOLD);
		ellipseStyle.put(mxConstants.STYLE_INDICATOR_HEIGHT, "90");
		
		Hashtable<String, Object> rectangularStyle = new Hashtable<String, Object>();
		rectangularStyle.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_RECTANGLE);
		rectangularStyle.put(mxConstants.STYLE_FILLCOLOR, "#8FB0D2");
		rectangularStyle.put(mxConstants.STYLE_STROKECOLOR, "#34526C");
		rectangularStyle.put(mxConstants.STYLE_STROKEWIDTH, 1.2);
		rectangularStyle.put(mxConstants.STYLE_FONTCOLOR, "#FFFFFF");
		rectangularStyle.put(mxConstants.STYLE_FONTFAMILY, "verdana");
		rectangularStyle.put(mxConstants.STYLE_FONTSTYLE, mxConstants.FONT_BOLD);
		rectangularStyle.put(mxConstants.STYLE_INDICATOR_HEIGHT, "90");
		
		// Estilo retangular destacado.
		Hashtable<String, Object> rectangularStyleHighlighted = new Hashtable<String, Object>();
		rectangularStyleHighlighted.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_RECTANGLE);
		rectangularStyleHighlighted.put(mxConstants.STYLE_FILLCOLOR, "#FFFFFF");
		rectangularStyleHighlighted.put(mxConstants.STYLE_STROKECOLOR, "#34526C");
		rectangularStyleHighlighted.put(mxConstants.STYLE_STROKEWIDTH, 1.2);
		rectangularStyleHighlighted.put(mxConstants.STYLE_FONTCOLOR, "#34526C");
		rectangularStyleHighlighted.put(mxConstants.STYLE_FONTFAMILY, "verdana");
		rectangularStyleHighlighted.put(mxConstants.STYLE_FONTSTYLE, mxConstants.FONT_BOLD);
		rectangularStyleHighlighted.put(mxConstants.STYLE_INDICATOR_HEIGHT, "90");

		mxStylesheet stylesheet = graph.getStylesheet();
		
		stylesheet.putCellStyle(ELLIPSE_STYLE, ellipseStyle);
		stylesheet.putCellStyle(RECTANGULAR_STYLE, rectangularStyle);
		stylesheet.putCellStyle(RECTANGULAR_STYLE_HIGHLIGHTED, rectangularStyleHighlighted);
        
        return graph;
	}
}
